package com.xfly.app.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ptmall.app.BuildConfig;
import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.net.HttpMethods;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.utils.GlideUtil;
import com.ptmall.app.utils.SharedPreferenceUtil;
import com.ptmall.app.view.CircularImage;
import com.ptmall.app.view.TitleBarView;
import com.xfly.app.bean.UserBean;

public class SetActivity  extends BaseMvpActivity {

    ApiDataRepository apiDataRepository = ApiDataRepository.getInstance();

    CircularImage topimg;
    TextView name,sharecode,typename,versionname;
    TitleBarView title_bar;
    TextView editinfo;

    Button lgout;

    LinearLayout repass,fk,dz;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_set);
    }

    @Override
    public void initViews() {
        topimg = findViewById(R.id.topimg);
        name = findViewById(R.id.name);
        sharecode = findViewById(R.id.sharecode);
        typename = findViewById(R.id.typename);
        versionname = findViewById(R.id.versionname);
        title_bar = findViewById(R.id.title_bar);
        lgout = findViewById(R.id.lgout);
        editinfo = findViewById(R.id.editinfo);
        repass = findViewById(R.id.repass);
        fk = findViewById(R.id.fk);
        dz = findViewById(R.id.dz);
    }

    @Override
    public void initEvents() {
        versionname.setText(BuildConfig.VERSION_NAME);

        title_bar.setText("设置");
        title_bar.setOnTitleBarClickListener(new TitleBarView.TitleBarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {

            }
        });

        repass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(getContext(),RePassActivity.class);
                startActivity(intent);
            }
        });

        dz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(getActivity(), Web.class);
                intent.putExtra("url", HttpMethods.BASE_SITE + "/cn/address/index");
                startActivity(intent);
            }
        });

        fk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(getContext(),FkActivity.class);
                startActivity(intent);
            }
        });

        lgout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(getContext(),XfLoginActivity.class);
                startActivity(intent);

                SharedPreferenceUtil.setSharedStringData(getContext(),"token","");
                finish();
            }
        });

        editinfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(getContext(),UserSetActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();

        getData();
    }

    private void getData(){
        apiDataRepository.myInfo(null, new ApiNetResponse<UserBean>(getContext()) {
            @Override
            public void onSuccess(UserBean data) {
                GlideUtil.showImg(getContext(),data.getAvatar(),topimg);
                name.setText(data.getName());
                sharecode.setText(data.getId()+"");
                switch (data.getGroup()){
                    case 0:
                        typename.setText("游客");
                        break;
                    case 1:
                        typename.setText("普通用户");
                        break;
                    case 2:
                        typename.setText("合伙人");
                        break;
                    case 3:
                        typename.setText("代理商");
                        break;
                }
            }
        });
    }
}
